#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<queue>

using namespace std;
#define RADIX 10

vector<queue<int>> vqi(RADIX);

int GetMaxNumDigit(vector<int>& v)
{
	int max = -1;
	int cnt = 0;
	for (const auto& e : v)
	{
		if (e > max)
		{
			max = e;
		}
	}
	while (max > 0)
	{
		max /= 10;
		cnt++;
	}
	return cnt;
}

int GetKey(int value, int k)
{
	int key = 0;
	while (k >= 0)
	{
		key = value % 10;
		value /= 10;
		k--;
	}
	return key;
}

void Distribute(vector<int>& v, int left, int right, int k)
{
	for (int i = left; i < right; i++)
	{
		int key = GetKey(v[i], k);
		vqi[key].push(v[i]);
	}
	vector<queue<int>> cpy(vqi);
	for (int i = 0; i < RADIX; i++)
	{
		cout << i << ':';
		if (cpy[i].empty())
		{
			cout << "NULL" << endl;
			continue;
		}
		while (!cpy[i].empty())
		{
			cout << "->" << cpy[i].front();
			cpy[i].pop();
		}
		
		cout << "->^" << endl;
	}
}

void Collect(vector<int>& v)
{
	int k = 0;
	for (int i = 0; i < RADIX; i++)
	{
		while (!vqi[i].empty())
		{
			v[k++] = vqi[i].front();
			vqi[i].pop();
		}
	}
}

void RadixSort(vector<int>& v, int left, int right)
{
	int k = GetMaxNumDigit(v);
	for (int i = 0; i < k; i++)
	{
		Distribute(v, left, right, i);
		Collect(v);
		for (int j = left; j < right; j++)
		{
			cout << v[j];
			if (j < right - 1)
			{
				cout << ' ';
			}
		}
		cout << endl;
	}
}

void test3()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		vector<int> v(n, 0);
		for (auto& e : v)
		{
			cin >> e;
		}
		RadixSort(v, 0, n);
		cout << endl;
	}
}

int main()
{
	test3();
	return 0;
}
